#include<iostream>
#include<vector>
#include<functional>
#include<algorithm>

using namespace std;

class MyPrint:public binary_function<int,int,void>
{
    public:
    void operator()(int v, int start) const{
        cout<<v+start<<endl;
    }
};

void test01(){
    vector<int> v;
    for(int i=0;i<10;i++){
        v.push_back(i);
    }
    cout<<"shuru"<<endl;
    int num;
    cin>>num;

    //适配器使用步骤：
    //绑定数据 bind2nd
    //继承类 binary_function<参数类型1，参数类型2，返回值类型>
    //加const修饰 operator()
    for_each(v.begin(),v.end(),bind2nd(MyPrint(), num));

}

//一元取反适配器
//步骤：
//一元取反适配器 not1
//继承unary_function<参数类型1， 返回值类型>
//const 修饰
class GreaterThanFive: public unary_function<int,bool>
{
    public:
    bool operator()(int v)const{
        return v>5;
    }
};

void test02(){
    vector<int> v;
    for(int i = 0; i<10;i++){
        v.push_back(i);
    }
    vector<int>::iterator pos = find_if(v.begin(), v.end(), not1(GreaterThanFive()));


    vector<int>::iterator pos = find_if(v.begin(), v.end(), not1(bind2nd(greater<int>(),5)));

}

//函数指针适配器
void MyPrint03(int v, int start){
    cout<<v<<" ";
}

void test03(){
    vector<int> v;
    for(int i=0;i<10;i++){
        v.emplace_back(i);
    }
    //将函数指针，适配为函数对象 
    //ptr_fun
    for_each(v.begin(), v.end(), bind2nd(ptr_fun(MyPrint03),100));
}

//成员函数适配器
class Person
{
    public:
    Person(string name, int age)
    {
        m_Name = name;
        m_Age = age;
    }
    void showPerson(){
        cout<<m_Name<<endl;
    }
    string m_Name;
    int m_Age;
};

void test04()
{
    Person p1("aaa", 3);
    vector<Person> v;
    v.emplace_back(p1);

    //成员函数适配器

    for_each(v.begin(), v.end(),mem_fun_ref(&Person::showPerson));
}

int main(){

    return 0;
}